package com.dkt.api.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dkt.api.domain.ItemMapper;
import com.dkt.api.web.dto.ItemDto;
import com.dkt.base.StrUtil;
import com.dkt.base.domain.Item;

@Service
public class ItemSrvImpl implements ItemSrv {

	@Autowired
	private ItemMapper itemMapper;

	@Override
	public List<Item> itemList(ItemDto itemDto) {
		if (itemDto.getName() == null) {
			itemDto.setName("");
		}
		Integer page = 1;
		try {
			page = Integer.parseInt(itemDto.getPage());
		} catch (NumberFormatException e) {

		}

		return itemMapper.selItem(itemDto.getName(), (page - 1) * 10);
	}

	@Override
	public void addItem(ItemDto itemDto) {
		Item item = new Item();
		item.setId(StrUtil.genUUID());
		item.setName(itemDto.getName());
		item.setImgs(itemDto.getImgs());
		item.setDesc(itemDto.getDesc());
		item.setPrice(Integer.parseInt(itemDto.getPrice()));
		item.setShopId(itemDto.getShopId());
		
		itemMapper.insItem(item);

	}
	
	

}
